/**
 * @author        Nicolas Bottarini <nicolasbottarini@gmail.com>, 404 <http://www.proyecto404.com>
 * @version       $Rev: 3 $
 * @lastrevision  $Date: 2011-09-12 16:45:37 +0000 (Mon, 12 Sep 2011) $	 
 */
package com.proyecto404.core.configuration {
	import com.proyecto404.core.TranslationManager;
	import com.proyecto404.core.collections.Dictionary;
	import com.proyecto404.core.collections.IIterator;
	import com.proyecto404.core.exception.InvalidOperationException;
	import com.proyecto404.core.mvc.ViewInfo;
	import com.proyecto404.core.util.StringHelper;

	public class ViewsConfigurationHandler extends ConfigurationHandler {
		private var _views:Dictionary;
		private var _namespace:String;
		
		public function ViewsConfigurationHandler(name:String) {
			super(name);
			_views = new Dictionary();
		}
		
		public override function addConfigurations(xmlData:XML):void {
			_namespace = (xmlData.@namespace).toString();
			
			for each(var node:XML in xmlData.children()) {
				var name:String = node.name().toString();
				switch(name) {
					case "view":
						var viewName:String = (node.@name).toString();
						var className:String = (node.@["class"]).toString();
						var preloadedWith:String = (node.@["preloadedWith"]).toString();
						if (className.length == 0) {
							className = (_namespace.length == 0 ? "" : _namespace + ".") + viewName;
						}
						var file:String = (node.@file).toString();
						_views.add(viewName, new ViewInfo(viewName, className, file, preloadedWith));
						break;
					default:
						throw new InvalidOperationException("Invalid node: " + name);
						break;
				}
			}
		}
		
		public override function get(configuration:String):* { 
			return _views.get(configuration); 
		}
		
		public override function contains(configuration:String):Boolean {
			return _views.containsKey(configuration);
		}
		
		public override function getConfigurations():IIterator {
			return _views.getValues().getIterator();		
		}
	}
}